package com.rc.web.controller;

import com.mybatisflex.core.paginate.Page;
import com.rc.common.annotate.WithoutTenant;
import com.rc.pojo.dto.area.AreaAddDTO;
import com.rc.pojo.dto.area.AreaPageQuery;
import com.rc.pojo.dto.area.AreaSeasonalDTO;
import com.rc.pojo.dto.area.AreaUpdateDTO;
import com.rc.pojo.vo.area.AreaSeasonalVO;
import com.rc.pojo.vo.area.AreaVO;
import com.rc.pojo.vo.area.PageAreaVO;
import com.rc.web.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  控制层。
 *
 * @author sym
 * @since 2024-05-26
 */
@RestController
@RequestMapping("/area")
@Api(tags = "园区")
@Validated
@RequiredArgsConstructor
public class AreaController {
    private final AreaService areaService;

    @PostMapping
    @ApiOperation("添加")
    public void add(@Validated @RequestBody AreaAddDTO dto){
        areaService.add(dto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public void deleteOneById(@PathVariable Long id){
        areaService.deleteOneById(id);
    }

    @PutMapping
    @ApiOperation("修改")
    public void updateById(@Validated @RequestBody AreaUpdateDTO dto){
        areaService.updateOneById(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation("农庄管理员查看园区详情")
    public AreaVO getOneById(@PathVariable Long id){
        return areaService.getOneById(id);
    }

    @GetMapping("/list")
    @ApiOperation("列表")
    public List<AreaVO> getList(){
        return areaService.getList();
    }

    @GetMapping("/page")
    @ApiOperation("分页")
    public Page<PageAreaVO> getPage(AreaPageQuery dto){
        return areaService.getPage(dto);
    }

    @GetMapping("/seasonal")
    @ApiOperation("农场当季园区列表")
    @WithoutTenant
    public List<AreaSeasonalVO> seasonal(AreaSeasonalDTO dto){
        return areaService.seasonal(dto);
    }
}
